<template>
  <div class="project-setting-view ">
    <p class="project-setting-title">
      回复设置
      <span class="small-font-size ml20 text-secondary-color">
        开启后可以在问卷的公开查询页面对数据进行评论，管理员可以回复消息
      </span>
    </p>
    <el-divider />
    <el-form ref="writeSettingForm" :model="writeSettingForm" :rules="settingRules">
      <div class="setting-item">
        <p class="label">
          回复公开查询
          <el-tooltip class="item" content="开启后在公开查询页面数据后出现回复按钮，可以给管理人员留言，管理人员可以再次回复" effect="dark" placement="top-start">
            <i class="el-icon-warning" />
          </el-tooltip>
        </p>
        <el-switch
          v-model="writeSettingForm.openReply"
        />
      </div>
      <el-row>
        <p class="project-setting-sub-label">
          * 此功能仅在开启公开查询时生效
        </p>
      </el-row>
      <div class="submit-btn">
        <el-button type="primary" @click="saveSettingHandle">
          保存设置
        </el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import mixin from './mixin'
import {getSettingRequest, saveSettingRequest} from "../../../api/project/setting"

export default {
  name: 'ReplySetting',
  mixins: [mixin],
  data() {
    return {
      settingRules: {},
      writeSettingForm: {
        openReply: false
      }
    }
  },
  mounted() {
    this.queryUserProjectSetting()
  },
  methods: {
    queryUserProjectSetting() {
      getSettingRequest(this.formKey).then((res) => {
        if (res.data) {
          this.writeSettingForm = res.data
        }
      })
    },
    saveSettingHandle() {
      this.$refs['writeSettingForm'].validate((valid) => {
        if (valid) {
          this.writeSettingForm.formKey = this.formKey
          saveSettingRequest(this.writeSettingForm).then(() => {
            this.msgSuccess('保存成功')
            this.queryUserProjectSetting()
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "settting";

</style>
